/* eslint-disable react-hooks/exhaustive-deps */
import React from 'react';
import { Form, Button, Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import { If } from 'babel-plugin-jsx-control-statements';
import BusinessType from '@/utils/BusinessType';
import css from '../index.scss';

/**
 * 停车管理备案中新增备案中相关附件表单
 */
export default (props) => {
	const { parkLotAttachmentsInfoFile, form } = props;
	const ownerType = 0;
	const ownerId = 0;
	// const host = 'http://192.168.43.11:8080';
	const host = 'http://192.168.21.86:8080';
	const propertyRight = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getPropertyRight()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					propertyRight: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const permissionRight = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getPermissionRight()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					permissionRight: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const businessLicense = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getBusinessLicense()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					businessLicense: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const recommendation = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getRecommendation()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					recommendation: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const confirmationOfCompletion = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getConfirmationOfCompletion()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					confirmationOfCompletion: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const trafficOrganisationChart = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getTrafficOrganizationChart()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					trafficOrganisationChart: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const parkLotSettingList = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getParkSettingList()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					parkLotSettingList: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const serviceAndSafeSystem = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getServiceAndSafeSystem()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					serviceAndSafeSystem: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const manageOperateMaintainProject = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getManageOpeateMaintainProject()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					manageOperateMaintainProject: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const emergencyResponsePlan = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getEmergencyResponsePlan()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					emergencyResponsePlan: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	const others = {
		name: 'file',
		action: `${host}/oss/upload/${ownerType}/${ownerId}/${BusinessType.getOthers()}`,
		headers: {
			authorization: 'authorization-text',
		},
		onChange(info) {
			if (info.file.status === 'done') {
				message.success(`${info.file.name} file uploaded successfully`);
				form.setFieldsValue({
					others: [info.file.response.data.row.id],
				});
			} else if (info.file.status === 'error') {
				message.error(`${info.file.name} file upload failed.`);
			}
		},
	};
	return (
		<div>
			<Form.Item
				label="停车场产权单位证明"
				className={css.item_file}
				name="propertyRight"
				tooltip="请上传证明材料（复印件、盖鲜章）！"
			>
				<Upload {...propertyRight}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If condition={parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.propertyRight !== null}>
					{parkLotAttachmentsInfoFile.propertyRight.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item
				label="使用权证明材料"
				className={css.item_file}
				name="permissionRight"
				tooltip="请上传管理单位证明：产权单位的委托书、租赁、隶属、自营、共有、抵押等使用权证明材料（复印件、盖鲜章）"
			>
				<Upload {...permissionRight}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If condition={parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.permissionRight !== null}>
					{parkLotAttachmentsInfoFile.permissionRight.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item
				label="管理单位工商营业执照"
				className={css.item_file}
				name="businessLicense"
				tooltip="请上传管理单位工商营业执照（复印件、盖鲜章）"
			>
				<Upload {...businessLicense}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If condition={parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.businessLicense !== null}>
					{parkLotAttachmentsInfoFile.businessLicense.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item
				label="单位授权办件委托书"
				className={css.item_file}
				name="recommendation"
				tooltip="请上传经办人证明：单位授权办件委托书或介绍信（复印件、盖鲜章）"
			>
				<Upload {...recommendation}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If condition={parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.recommendation !== null}>
					{parkLotAttachmentsInfoFile.recommendation.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item label="建设工程规划竣工验收备案登记证" className={css.item_file} name="confirmationOfCompletion">
				<Upload {...confirmationOfCompletion}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If
					condition={
						parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.confirmationOfCompletion !== null
					}
				>
					{parkLotAttachmentsInfoFile.confirmationOfCompletion.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item
				label="交通组织图"
				className={css.item_file}
				name="trafficOrganisationChart"
				tooltip="请上传停车场交通组织图,包括：标志出入口，标志标线，停车泊位设置等信息（复印件、盖鲜章）"
			>
				<Upload {...trafficOrganisationChart}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If
					condition={
						parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.trafficOrganisationChart !== null
					}
				>
					{parkLotAttachmentsInfoFile.trafficOrganisationChart.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item
				label="停车场设施清单"
				className={css.item_file}
				name="parkLotSettingList"
				tooltip="停车场设施清单、立体机械式停车设备的特种设备注册登记证和质检部门出具的合格证书复印件壹份（复印件、盖鲜章）"
			>
				<Upload {...parkLotSettingList}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If
					condition={parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.parkLotSettingList !== null}
				>
					{parkLotAttachmentsInfoFile.parkLotSettingList.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item className={css.item_file}>
				<></>
			</Form.Item>
			<Form.Item
				label="经营服务及安全管理制度"
				className={css.item_file}
				name="serviceAndSafeSystem"
				tooltip="停车场管理制度（复印件、盖鲜章）:车辆停放、安全保卫、消防管理等方面的管理制度和安全防范措施及车库管理人员岗位职责等"
			>
				<Upload {...serviceAndSafeSystem}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If
					condition={
						parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.serviceAndSafeSystem !== null
					}
				>
					{parkLotAttachmentsInfoFile.serviceAndSafeSystem.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item
				label="管理运营维护方案"
				className={css.item_file}
				name="manageOperateMaintainProject"
				tooltip="停车场管理制度（复印件、盖鲜章）:停车场管理运营维护方案、消防维保记录（复印件、盖鲜章）"
			>
				<Upload {...manageOperateMaintainProject}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If
					condition={
						parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.manageOperateMaintainProject !== null
					}
				>
					{parkLotAttachmentsInfoFile.manageOperateMaintainProject.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item
				label="应急处理预案"
				className={css.item_file}
				name="emergencyResponsePlan"
				tooltip="停车场管理制度（复印件、盖鲜章）:应急处置预案（复印件、盖鲜章）"
			>
				<Upload {...emergencyResponsePlan}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If
					condition={
						parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.emergencyResponsePlan !== null
					}
				>
					{parkLotAttachmentsInfoFile.emergencyResponsePlan.map((item) => (
						<a href={item.path}>{item.name}</a>
					))}
				</If>
			</Form.Item>
			<Form.Item label="其他" className={css.item_file} name="others">
				<Upload {...others}>
					<Button icon={<UploadOutlined />}>上传</Button>
				</Upload>
				<If condition={parkLotAttachmentsInfoFile !== undefined && parkLotAttachmentsInfoFile.others !== null}>
					{parkLotAttachmentsInfoFile.others.map((item) => (
						<>
							<a href={item.path}>{item.name}</a>
							<br />
						</>
					))}
				</If>
			</Form.Item>
		</div>
	);
};
